Micron Document
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| SparkN0de-git | SparkN0de |
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


Commit 1a37f49d42690e70b55009855b5a110cc739fb7e


Parents : cff6621
Author : Sudo-Ivan <ivan@quad4.io>
Signature : Signature validation error
Date : 2026-03-05T15:17:19-06:00

Add tests for MicronParser and NomadNetworkPage to validate partial handling, including regex matching, content injection, and state management for partials.

Changes

2 files changed, 136 insertions(+), 0 deletions(-)


Diff

diff --git a/tests/frontend/MicronParser.test.js b/tests/frontend/MicronParser.test.js
index 37159441..008cc425 100644
--- a/tests/frontend/MicronParser.test.js
+++ b/tests/frontend/MicronParser.test.js
@@ -8,6 +8,34 @@ describe("MicronParser.js", () => {
parser = new MicronParser(true, false); // darkTheme = true, enableForceMonospace = false
});
+ describe("PARTIAL_LINE_REGEX", () => {
+ it("matches partial without refresh", () => {
+ const m = "`{f64a846313b874ee4a357040807f8c77:/page/partial.mu}"
+ .trim()
+ .match(MicronParser.PARTIAL_LINE_REGEX);
+ expect(m).not.toBeNull();
+ expect(m[1]).toBe("f64a846313b874ee4a357040807f8c77");
+ expect(m[2]).toBe("/page/partial.mu");
+ expect(m[3]).toBeUndefined();
+ });
+
+ it("matches partial with refresh", () => {
+ const m = "`{f64a846313b874ee4a357040807f8c77:/page/ref.mu`30}"
+ .trim()
+ .match(MicronParser.PARTIAL_LINE_REGEX);
+ expect(m).not.toBeNull();
+ expect(m[3]).toBe("30");
+ });
+
+ it("does not match without leading backtick", () => {
+ expect("{f64a846313b874ee4a357040807f8c77:/page/x.mu}".match(MicronParser.PARTIAL_LINE_REGEX)).toBeNull();
+ });
+
+ it("does not match short hash", () => {
+ expect("`{f64a846313b874ee4a35704:/page/x.mu}".match(MicronParser.PARTIAL_LINE_REGEX)).toBeNull();
+ });
+ });
+
describe("formatNomadnetworkUrl", () => {
it("formats nomadnetwork URL correctly", () => {
expect(MicronParser.formatNomadnetworkUrl("example.com")).toBe("nomadnetwork://example.com");
@@ -98,6 +126,69 @@ describe("MicronParser.js", () => {
expect(html).toContain('value="val"');
expect(html).toContain("Checkbox Label");
});
+
+ describe("partials", () => {
+ it("emits placeholder for partial line without refresh", () => {
+ const dest = "f64a846313b874ee4a357040807f8c77";
+ const path = "/page/partial_1.mu";
+ const markup = "`{" + dest + ":" + path + "}";
+ const html = parser.convertMicronToHtml(markup);
+ expect(html).toContain('class="mu-partial"');
+ expect(html).toContain('data-partial-id="partial-0"');
+ expect(html).toContain('data-dest="' + dest + '"');
+ expect(html).toContain('data-path="' + path + '"');
+ expect(html).not.toContain("data-refresh");
+ expect(html).toContain("Loading...");
+ });
+
+ it("emits placeholder for partial line with refresh seconds", () => {
+ const dest = "f64a846313b874ee4a357040807f8c77";
+ const path = "/page/refreshing_partial.mu";
+ const markup = "`{" + dest + ":" + path + "`10}";
+ const html = parser.convertMicronToHtml(markup);
+ expect(html).toContain('class="mu-partial"');
+ expect(html).toContain('data-partial-id="partial-0"');
+ expect(html).toContain('data-dest="' + dest + '"');
+ expect(html).toContain('data-path="' + path + '"');
+ expect(html).toContain('data-refresh="10"');
+ expect(html).toContain("Loading...");
+ });
+
+ it("injects partialContents when provided", () => {
+ const dest = "a".repeat(32);
+ const path = "/page/partial.mu";
+ const markup = "`{" + dest + ":" + path + "}";
+ const injected = "<span>Injected partial content</span>";
+ const html = parser.convertMicronToHtml(markup, { "partial-0": injected });
+ expect(html).toContain(injected);
+ expect(html).not.toContain("Loading...");
+ expect(html).not.toContain("mu-partial");
+ });
+
+ it("assigns unique partial ids for multiple partials", () => {
+ const dest = "b".repeat(32);
+ const markup = "`{" + dest + ":/page/a.mu}\n`{" + dest + ":/page/b.mu}";
+ const html = parser.convertMicronToHtml(markup);
+ expect(html).toContain('data-partial-id="partial-0"');
+ expect(html).toContain('data-partial-id="partial-1"');
+ expect(html).toContain('data-path="/page/a.mu"');
+ expect(html).toContain('data-path="/page/b.mu"');
+ });
+
+ it("does not interpret partial syntax inside literal block", () => {
+ const dest = "c".repeat(32);
+ const markup = "`=\n`{" + dest + ":/page/partial.mu}\n`=";
+ const html = parser.convertMicronToHtml(markup);
+ expect(html).not.toContain("mu-partial");
+ expect(html).toContain("`{" + dest + ":/page/partial.mu}");
+ });
+
+ it("does not treat similar-looking line as partial without backtick", () => {
+ const markup = "{f64a846313b874ee4a357040807f8c77:/page/partial.mu}";
+ const html = parser.convertMicronToHtml(markup);
+ expect(html).not.toContain("mu-partial");
+ });
+ });
});
describe("colorToCss", () => {

diff --git a/tests/frontend/NomadNetworkPage.test.js b/tests/frontend/NomadNetworkPage.test.js
index ad6070ad..a9840560 100644
--- a/tests/frontend/NomadNetworkPage.test.js
+++ b/tests/frontend/NomadNetworkPage.test.js
@@ -93,4 +93,49 @@ describe("NomadNetworkPage.vue", () => {
expect(wrapper.vm.isShowingNodePageSource).toBe(true);
}
});
+
+ describe("partials", () => {
+ it("clearPartials resets partial state and timers", () => {
+ const wrapper = mountNomadNetworkPage();
+ wrapper.vm.pagePartials = { "partial-0": "<span>x</span>" };
+ wrapper.vm.partialIdsByKey = { "abc:path": [] };
+ wrapper.vm.partialRefreshByKey = { "abc:path": 10 };
+ wrapper.vm.partialRefreshTimers = { "abc:path": 12345 };
+
+ wrapper.vm.clearPartials();
+
+ expect(wrapper.vm.pagePartials).toEqual({});
+ expect(wrapper.vm.partialIdsByKey).toEqual({});
+ expect(wrapper.vm.partialRefreshByKey).toEqual({});
+ expect(wrapper.vm.partialRefreshTimers).toEqual({});
+ });
+
+ it("renderPageContent with .mu and pagePartials injects partial content", () => {
+ const dest = "a".repeat(32);
+ const wrapper = mountNomadNetworkPage();
+ wrapper.vm.pagePartials = { "partial-0": "<span>Loaded partial</span>" };
+ const content = "Hello\n`{" + dest + ":/page/partial.mu}\nWorld";
+ const path = dest + ":/page/index.mu";
+
+ const html = wrapper.vm.renderPageContent(path, content);
+
+ expect(html).toContain("Loaded partial");
+ expect(html).not.toContain("Loading...");
+ expect(html).toContain("H");
+ expect(html).toContain("W");
+ });
+
+ it("renderPageContent without pagePartials shows placeholder for partial", () => {
+ const dest = "b".repeat(32);
+ const wrapper = mountNomadNetworkPage();
+ const content = "`{" + dest + ":/page/partial.mu}";
+ const path = dest + ":/page/index.mu";
+
+ const html = wrapper.vm.renderPageContent(path, content);
+
+ expect(html).toContain("mu-partial");
+ expect(html).toContain("Loading...");
+ expect(html).toContain('data-dest="' + dest + '"');
+ });
+ });
});


──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────